package org.xue.snowmall.group.service.impl;

import com.alibaba.fastjson.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.xue.snowmall.common.utils.PageUtils;
import org.xue.snowmall.common.utils.Query;

import org.xue.snowmall.common.utils.R;
import org.xue.snowmall.group.dao.GroupDao;
import org.xue.snowmall.group.entity.GroupEntity;
import org.xue.snowmall.group.feign.OrderFeignService;
import org.xue.snowmall.group.service.GroupService;


@Service("groupService")
public class GroupServiceImpl extends ServiceImpl<GroupDao, GroupEntity> implements GroupService {

    @Autowired
    private OrderFeignService orderFeignService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<GroupEntity> page = this.page(
                new Query<GroupEntity>().getPage(params),
                new QueryWrapper<GroupEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public R createGroupOrder(Long gsmGroupId) {

        //远程调用订单服务生成订单
        R groupOrder = orderFeignService.createGroupOrder(gsmGroupId);
        Long osmId = groupOrder.getData("osmId", new TypeReference<Long>() {
        });
        return R.ok().put("osmId",osmId);
    }


}